//
//  AIMineThreeButtonView.m
//  ZJCLoveBee
//
//  Created by 朱建超 on 16/12/22.
//  Copyright © 2016年 itHeiMa. All rights reserved.
//

#import "AIMineThreeButtonView.h"
#import "Masonry.h"
#import "AIMineButton.h"
#import "AIMineMyOrderController.h"

@interface AIMineThreeButtonView ()

@property(nonatomic,copy)NSMutableArray <UIButton *> *buttonMArray;

@end

@implementation AIMineThreeButtonView

-(instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
        
//        self.backgroundColor = [UIColor yellowColor];
        
    }
    return self;
}

#pragma mark - 布局按钮
-(void)setupUI{
        
    //创建一个title数组
    NSArray *titleArray = @[@"我的订单",@"优惠券",@"我的消息"];
    
    //创建一个数组
    NSMutableArray <UIButton *> *buttonMArray = [NSMutableArray array];
    
    _buttonMArray = buttonMArray;
    
    //添加按钮
    NSInteger index = 0;
    
    for (NSString *title in titleArray) {
        
        AIMineButton *button = [AIMineButton buttonWithType:UIButtonTypeCustom];
        
        [button setTitle:title forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        button.tag = index++;
        
        [self addSubview:button];
        
        [buttonMArray addObject:button];
        
        //添加按钮的监听事件
        [button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    [buttonMArray[0] setImage:[UIImage imageNamed:@"v2_my_order_icon"] forState:UIControlStateNormal];
    [buttonMArray[1] setImage:[UIImage imageNamed:@"v2_my_coupon_icon"] forState:UIControlStateNormal];
    [buttonMArray[2] setImage:[UIImage imageNamed:@"v2_my_message_icon"] forState:UIControlStateNormal];
    
    //布局约束
    [buttonMArray[0] mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.bottom.mas_equalTo(self);
        
    }];
    
    [buttonMArray[1] mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(buttonMArray[0].mas_top);
        make.left.mas_equalTo(buttonMArray[0].mas_right);
        make.size.mas_equalTo(buttonMArray[0]);
        
    }];
    
    [buttonMArray[2] mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(buttonMArray[1].mas_top);
        make.left.mas_equalTo(buttonMArray[1].mas_right);
        make.size.mas_equalTo(buttonMArray[1]);
        make.right.mas_equalTo(self.mas_right);
    }];

}

-(void)clickButton:(UIButton *)button{

    [[NSNotificationCenter defaultCenter] postNotificationName:@"goToController" object:nil userInfo:@{@"btnTag":@(button.tag)}];

}

-(void)dealloc{

    [[NSNotificationCenter defaultCenter] removeObserver:self];

}

@end
